home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / VideoToolbox 96.06.15 / VideoToolboxSources / CopyQuickDrawGlobals.c < prev    next >
Text File  |  1994-06-03  |  2KB  |  51 lines

  1. /*
  2. CopyQuickDrawGlobals.c
  3. This is a workaround for a silly limitation of THINK C. THINK C allows you to
  4. implicitly initialize QuickDraw by calling a console function, e.g. printf(),
  5. rather than explicitly initialize QuickDraw by calling InitGraf etc. In the
  6. first case THINK C then supports full input and output through the console and
  7. also handles events, e.g. Command-. will cause an abort. (If you explicitly
  8. initialize QuickDraw you can only use the console for output, not input.)
  9. However, when THINK C does its own initialization it uses a private QuickDraw
  10. "globals" area instead of the one at qd. This happened because Symantec didn't
  11. want to force users of the console in the ANSI library to have to load the
  12. MacTraps library (where qd is located). The consequence of this is that if your
  13. program lets the console implicitly initialize QuickDraw then all the QuickDraw
  14. globals, e.g. the Patterns white and black, are all zero.
  15.  
  16. This program is a quick fix. It copies the real QuickDraw globals, referenced
  17. off of register A5 to the public qd. It is totally safe. You can call it at any
  18. time and as many times as you want. Of course there is little point in copying
  19. the QuickDraw globals before they have been initialized, typically by your first
  20. call to printf.
  21.  
  22. The only side effect of this program (other than updating your quickdraw globals)
  23. is that register A5 is loaded from low-memory global CurrentA5. I cannot
  24. imagine a circumstance in which this would be bad since virtually all
  25. Mac programs assume that the two are equal.
  26.  
  27. If MATLAB is true then "qd" will have been redefined as "mex_qd".
  28.  
  29. HISTORY:
  30. 1/17/92    dgp    Wrote it based on a suggestion of Mike Kahl.
  31. 1/22/92 dgp    Eliminated asm.
  32. 3/10/92 dgp    Eliminated erroneous assumption that sizeof(qd) was a multiple of four.
  33.             Only copy the standard public quickdraw globals.
  34. 1/25/93 dgp removed obsolete support for THINK C 4.
  35. 1/25/93    dgp Replaced SysEqu.h by LoMem.h and changed program accordingly.
  36. 2/1/93    dgp    Corrected the capitalization of QuickDraw throughout this file.
  37. 6/3/94    dgp    Eliminated use of low-memory global CurrentA5 by instead calling
  38.             SetCurrentA5().
  39. */
  40. #include "VideoToolbox.h"
  41.  
  42. void CopyQuickDrawGlobals(void)
  43. {
  44.     register short *s,*d;
  45.     
  46.     s=*(short **)SetCurrentA5();
  47.     d=(short *)&qd.thePort;
  48.     s+=sizeof(qd.thePort)/sizeof(short);
  49.     d+=sizeof(qd.thePort)/sizeof(short);
  50.     while(d!=(short *)&qd.randSeed) *--d = *--s;
  51. }